package com.b2c.ftysys.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.b2c.ftysys.domain.ExampleFactory;
import com.b2c.ftysys.domain.PageResult;
import com.b2c.ftysys.domain.Product;
import com.b2c.ftysys.sevice.ProductService;
import com.b2c.ftysys.sevice.WsInfoService;

@Controller
public class ProductAction {

	@Autowired
	WsInfoService wsInfoService = null;

	@Autowired
	ProductService productService = null;

	@RequestMapping("/proPrice")
	public String toProductPriceSettingPage(HttpServletRequest request) {
		request.setAttribute("wsDataList", wsInfoService.queryAllWs());
		return "product/proPrice";
	}

	@RequestMapping("getProduct.do")
	public String toOrderItemsPage(HttpServletRequest request) {
		String sku = request.getParameter("sku");
		String orderId = request.getParameter("orderId");
		PageResult page = new PageResult();
		page.setSqlParamObj(ExampleFactory.createPdtOrderExample());
		request.setAttribute("sku", sku);
		request.setAttribute("orderId", orderId);
		request.setAttribute("dataList",
				productService.getProductByOrderIdSku(orderId, sku));
		return "product/productList";
	}

	@RequestMapping("getFtySku")
	public String getFtySku(HttpServletRequest request,
			HttpServletResponse response) {
		String sku = request.getParameter("q");
		if (StringUtils.isEmpty(sku))
			return null;
		for (Product product : this.productService.seachByCmtSku(sku
				.toUpperCase())) {
			try {
				response.getWriter().println(product.getPdtskuid());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
}
